#include "catch.hpp"
#include "ACEtk.hpp"

using namespace njoy::ACEtk;

namespace {

class Data : public Table::Data {
public:
  using Parse = Table::Data::Parse; 
};

}

SCENARIO("XSS parsing"){
  int nEntries = 74;
  
  SECTION("A correct XSS"){
    std::string XSS =
      "   1.00000000000E-11   1.03125000000E-11   1.06250000000E-11   1.09375000000E-11\n"
      "   1.12500000000E-11   1.15625000000E-11   1.18750000000E-11   1.21875000000E-11\n"
      "   1.25000000000E-11   1.28125000000E-11   1.31250000000E-11   1.34375000000E-11\n"
      "   1.37500000000E-11   1.43750000000E-11   1.50000000000E-11   1.56250000000E-11\n"
      "   1.62500000000E-11   1.68750000000E-11   1.75000000000E-11   1.81250000000E-11\n"
      "   1.87500000000E-11   1.93750000000E-11   2.00000000000E-11   2.09375000000E-11\n"
      "   2.18750000000E-11   2.28125000000E-11   2.37500000000E-11   2.46875000000E-11\n"
      "   2.56250000000E-11   2.65625000000E-11   2.75000000000E-11   2.84375000000E-11\n"
      "   2.93750000000E-11   3.03125000000E-11   3.12500000000E-11   3.21875000000E-11\n"
      "   3.31250000000E-11   3.40625000000E-11   3.50000000000E-11   3.59375000000E-11\n"
      "   3.68750000000E-11   3.78125000000E-11   3.87500000000E-11   3.96875000000E-11\n"
      "   4.06250000000E-11   4.25000000000E-11   4.43750000000E-11   4.62500000000E-11\n"
      "   4.81250000000E-11   5.00000000000E-11   5.15625000000E-11   5.31250000000E-11\n"
      "   5.46875000000E-11   5.62500000000E-11   5.78125000000E-11   5.93750000000E-11\n"
      "   6.09375000000E-11   6.25000000000E-11   6.40625000000E-11   6.56250000000E-11\n"
      "   6.71875000000E-11   6.87500000000E-11   7.18750000000E-11   7.50000000000E-11\n"
      "   7.81250000000E-11   8.12500000000E-11   8.43750000000E-11   8.75000000000E-11\n"
      "   9.06250000000E-11   9.37500000000E-11   9.68750000000E-11   1.00000000000E-10\n"
      "   1.03125000000E-10   1.06250000000E-10\n";

    std::vector<double> xss = {
          1.00000000000E-11,   1.03125000000E-11,   1.06250000000E-11,   1.09375000000E-11,
          1.12500000000E-11,   1.15625000000E-11,   1.18750000000E-11,   1.21875000000E-11,
          1.25000000000E-11,   1.28125000000E-11,   1.31250000000E-11,   1.34375000000E-11,
          1.37500000000E-11,   1.43750000000E-11,   1.50000000000E-11,   1.56250000000E-11,
          1.62500000000E-11,   1.68750000000E-11,   1.75000000000E-11,   1.81250000000E-11,
          1.87500000000E-11,   1.93750000000E-11,   2.00000000000E-11,   2.09375000000E-11,
          2.18750000000E-11,   2.28125000000E-11,   2.37500000000E-11,   2.46875000000E-11,
          2.56250000000E-11,   2.65625000000E-11,   2.75000000000E-11,   2.84375000000E-11,
          2.93750000000E-11,   3.03125000000E-11,   3.12500000000E-11,   3.21875000000E-11,
          3.31250000000E-11,   3.40625000000E-11,   3.50000000000E-11,   3.59375000000E-11,
          3.68750000000E-11,   3.78125000000E-11,   3.87500000000E-11,   3.96875000000E-11,
          4.06250000000E-11,   4.25000000000E-11,   4.43750000000E-11,   4.62500000000E-11,
          4.81250000000E-11,   5.00000000000E-11,   5.15625000000E-11,   5.31250000000E-11,
          5.46875000000E-11,   5.62500000000E-11,   5.78125000000E-11,   5.93750000000E-11,
          6.09375000000E-11,   6.25000000000E-11,   6.40625000000E-11,   6.56250000000E-11,
          6.71875000000E-11,   6.87500000000E-11,   7.18750000000E-11,   7.50000000000E-11,
          7.81250000000E-11,   8.12500000000E-11,   8.43750000000E-11,   8.75000000000E-11,
          9.06250000000E-11,   9.37500000000E-11,   9.68750000000E-11,   1.00000000000E-10,
          1.03125000000E-10,   1.06250000000E-10 };

    State< std::string::iterator > s{ 1, XSS.begin(), XSS.end() };
    auto result = Data::Parse::XSS( s, nEntries );
    REQUIRE( s.lineNumber == 20 );
    /*
    for ( unsigned i = 0; i < xss.size(); ++i ){
      auto error = std::abs( ( xss[i] - result[i] ) / xss[i] );
      REQUIRE( error < 1E-15 );
    }
    */
  }

  SECTION("A incorrect XSS"){
    std::string XSS =
      "   1.00000000000E-11   1.03125000000E-11   1.06250000000E-11   1.09375000000E-11\n"
      "   1.12500000000E-11   1.15625000000E-11   1.18750000000E-11   1.21875000000E-11\n"
      "   1.25000000000E-11   1.28125000000E-11   1.31250000000E-11   1.34375000000E-11\n"
      "   1.37500000000E-11   1.43750000000E-11   1.50000000000E-11   1.56250000000E-11\n"
      "   1.62500000000E-11   1.68750000000E-11   1.75000000000E-11   1.81250000000E-11\n"
      "   1.87500000000E-11   1.93750000000E-11   2.00000000000E-11   2.09375000000E-11\n"
      "   2.18750000000E-11   2.28125000000E-11   2.37500000000E-11   2.46875000000E-11\n"
      "   2.56250000000E-11   2.65625000000E-11   2.75000000000E-11   2.84375000000E-11\n"
      "   2.93750000000E-11   3.03125000000E-11   3.12500000000E-11   3.21875000000E-11\n"
      "   3.31250000000E-11   3.40625000000E-11   3.50000000000E-11   3.59375000000E-11\n"
      "   3.68750000000E-11   3.78125000000E-11          I AM GROOT   3.96875000000E-11\n"
      "   4.06250000000E-11   4.25000000000E-11   4.43750000000E-11   4.62500000000E-11\n"
      "   4.81250000000E-11   5.00000000000E-11   5.15625000000E-11   5.31250000000E-11\n"
      "   5.46875000000E-11   5.62500000000E-11   5.78125000000E-11   5.93750000000E-11\n"
      "   6.09375000000E-11   6.25000000000E-11   6.40625000000E-11   6.56250000000E-11\n"
      "   6.71875000000E-11   6.87500000000E-11   7.18750000000E-11   7.50000000000E-11\n"
      "   7.81250000000E-11   8.12500000000E-11   8.43750000000E-11   8.75000000000E-11\n"
      "   9.06250000000E-11   9.37500000000E-11   9.68750000000E-11   1.00000000000E-10\n"
      "   1.03125000000E-10   1.06250000000E-10\n";

    State< std::string::iterator > s{ 1, XSS.begin(), XSS.end() };
    //REQUIRE_THROWS( Data::Parse::XSS( s, nEntries ) );
  }
}
